package ferp.core.state;

import ferp.core.game.Game;
import ferp.core.game.Input;
import ferp.core.game.Settings;
import ferp.core.mode.Mode;
import ferp.core.player.Player;
import ferp.core.player.Profile;

/**
 * User: olegs
 * Date: 2/1/13 12:33 PM
 */
public class Replay extends State
{
  @Override
  public int process(Game.Listener listener, Profile profile, Game g, Settings settings, Input input) throws Game.Error
  {
    // switch to bidding mode
    g.set(Mode.bidding);

    // reset the game object
    g.reset();

    // restore the initial hands, must not be cleared by Game.reset()
    for (Player player : g.players())
    {
      Game.HandData hand = g.getHand(player.id());

      hand.current = hand.initial;
    }

    listener.onReplayStarted(g);

    // save the game state
    save(profile);

    return Result.SCHEDULE;
  }
}
